package org.wattdepot.cli.command;

import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.wattdepot.cli.processor.CommandLineInterface;
import static org.junit.Assert.assertTrue;

/**
 * TotalGenerated command test case, evaluates command against known values.
 * 
 * @author Bao Huy Ung, Edward Meyer
 */
public class TestTotalGenerated extends CommandLineInterface {

  /**
   * Tests if command TotalGenerated return valid known values.
   */
  @Test
  public void testPower() {

    List<String> args = new ArrayList<String>();

    boolean totalCheck = false;

    // add command to be taken by cli
    args.add("total");
    args.add("energy");
    args.add("generated");
    args.add("SIM_WAIAU_8");
    args.add("day");
    args.add("2009-11-15");
    args.add("sampling-interval");
    args.add("30");

    TotalGenerated total = new TotalGenerated();
    String testOut = total.doCommand(args);

    if (testOut.equalsIgnoreCase("1.7164902774691358E9")) {
      totalCheck = true;
    }

    System.out.println("Sampling known energy value Source: SIM_WAIAU_8 on 2009-11-15");
    assertTrue("Check SIM_WAIAU_8 energy on 2009-11-15", totalCheck);

    // second test value for known energy output
    args.set(3, "SIM_OAHU_GRID");

    testOut = total.doCommand(args);

    if (testOut.equalsIgnoreCase("1.4080360277469135E10")) {
      totalCheck = true;
    }
    else {
      totalCheck = false;
    }

    System.out.println("Sample known energy value Source: SIM_OAHU_GRID on 2009-11-15");
    assertTrue("Check SIM_OAHU_GRID energy on 2009-11-15", totalCheck);

    // test values for known carbon output
    args.set(1, "carbon");
    args.set(3, "SIM_WAIAU_8");

    testOut = total.doCommand(args);

    if (testOut.equalsIgnoreCase("3089682.4994444447")) {
      totalCheck = true;
    }
    else {
      totalCheck = false;
    }

    System.out.println("Sample known carbon value Source: SIM_WAIAU_8 on 2009-11-15");
    assertTrue("Check SIM_WAIAU_8 carbon on 2009-11-15", totalCheck);

    // second test value for known carbon output
    args.set(3, "SIM_OAHU_GRID");

    testOut = total.doCommand(args);

    if (testOut.equalsIgnoreCase("2.7869578610555556E7")) {
      totalCheck = true;
    }
    else {
      totalCheck = false;
    }

    System.out.println("Sample known carbon value Source:SIM_OAHU_GRID on 2009-11-15");
    assertTrue("SIM_OAHU_GRID carbon on 2009-11-15", totalCheck);

  }

}